from PIL import Image, ImageDraw
import os
import sys

def create_program_icons():
    """创建程序图标（ICO和ICNS格式）"""
    # 加载原始PNG图标
    icon_sizes = [(16, 16), (32, 32), (48, 48), (64, 64), (128, 128), (256, 256)]
    icons = []
    
    for size in icon_sizes:
        # 创建图标
        image = Image.new('RGBA', size, color=(0, 0, 0, 0))
        dc = ImageDraw.Draw(image)
        
        # 计算圆的大小
        margin = size[0] // 11
        circle_box = [margin, margin, size[0]-margin, size[1]-margin]
        
        # 绘制外圈和内圈
        dc.ellipse(circle_box, outline='blue', width=max(1, size[0]//22))
        inner_margin = size[0] // 4
        inner_box = [inner_margin, inner_margin, size[0]-inner_margin, size[1]-inner_margin]
        dc.ellipse(inner_box, fill='blue')
        
        icons.append(image)
    
    # 确保目标目录存在
    icon_path = os.path.join(os.path.dirname(os.path.dirname(__file__)), 'ws_notifier', 'gui', 'assets')
    os.makedirs(icon_path, exist_ok=True)
    
    # 保存 ICO 文件 (Windows)
    ico_file = os.path.join(icon_path, 'icon.ico')
    icons[0].save(ico_file, format='ICO', sizes=[(x, x) for x in [16, 32, 48, 64, 128, 256]])
    print(f"Created ICO file at: {ico_file}")
    
    # 保存 PNG 文件 (通用)
    png_file = os.path.join(icon_path, 'icon.png')
    icons[0].save(png_file, format='PNG')
    print(f"Created PNG file at: {png_file}")
    
    # 保存 ICNS 文件 (MacOS)
    if sys.platform == 'darwin':
        icns_file = os.path.join(icon_path, 'icon.icns')
        icons[0].save(icns_file, format='ICNS')
        print(f"Created ICNS file at: {icns_file}")

if __name__ == '__main__':
    create_program_icons() 